package com.yungu.swift.order.utils;

import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.constants.OrderConstant;
import com.yungu.swift.order.model.vo.PayVo;
import com.yungu.swift.utils.StringUtils;

/**
 * @author cuixiuyin on 2018/12/6.
 */
public class PayLogBuilder {

    public static void buildLog(PayVo payVo) {
        //设置标题
        payVo.setSubject(getSubject(payVo));
        //初始化日志
        appendLog(payVo, String.format("%s --订单[ %s ]--发起者[ %s ]", payVo.getSubject(), payVo.getOrderUuid(), payVo.getUserUuid()));
    }

    public static void prependLog(PayVo payVo, String prependStr) {
        payVo.setDescription((StringUtils.isEmpty(payVo.getDescription()) ? "" : prependStr + payVo.getDescription()));
    }

    public static void appendLog(PayVo payVo, String appendStr) {
        payVo.setDescription((StringUtils.isEmpty(payVo.getDescription()) ? "" : payVo.getDescription()) + appendStr);
    }

    public static String getSubject(PayVo payVo) {
        return getPaySideStr(payVo) + getPayTypeStr(payVo) + getPayPurposeStr(payVo);
    }

    public static String getPaySideStr(PayVo payVo) {
        if (payVo.getPaySide() == CommonConstant.PASSENGER) {
            return "[乘客]";
        }
        if (payVo.getPaySide() == CommonConstant.DRIVER) {
            return "[司机]";
        }
        if (payVo.getPaySide() == CommonConstant.PASSENGER_H5) {
            return "[乘客][H5]";
        }
        if (payVo.getPaySide() == CommonConstant.PASSENGER_APPLET) {
            return "[乘客][小程序]";
        }
        return "[不合法的支付端]";
    }

    public static String getPayTypeStr(PayVo payVo) {
        if (payVo.getPayType() == OrderConstant.PAY_TYPE_TENPAY) {
            return "[微信]";
        }
        if (payVo.getPayType() == OrderConstant.PAY_TYPE_ALIPAY) {
            return "[支付宝]";
        }
        if (payVo.getPayType() == OrderConstant.PAY_TYPE_BALANCE) {
            return "[余额]";
        }
        return "[不合法的支付类型]";
    }

    public static String getPayPurposeStr(PayVo payVo) {
        if (payVo.getPayPurpose() == OrderConstant.PAY_PURPOSE_CHARGE_FARE) {
            return "[支付车费]";
        }
        if (payVo.getPayPurpose() == OrderConstant.PAY_PURPOSE_RECHARGE_ACCOUNT) {
            return "[充值账户]";
        }
        return "[不合法的支付目的]";
    }

}
